package com.hue.gulimail.gulimailgetway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * 通过网关来同一配置跨域请求的访问
 */
@Configuration
public class GulimailCorsConfiguration {
    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration = new CorsConfiguration();
        //跨域配置
        configuration.addAllowedHeader("*");    //所有的请求头可以跨域
        configuration.addAllowedMethod("*");    //所有的请求方法可以跨域
        configuration.addAllowedOrigin("*");    //所有的来源可以跨域
        configuration.setAllowCredentials(true);    //允许请求携带cookie信息
        source.registerCorsConfiguration("/**",configuration);

        return new CorsWebFilter(source);
    }
}
